package com.rem.chat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rem.chat.pojo.dataobject.GroupInfoDO;
import com.rem.chat.service.dto.GroupInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author: Themberfue
 * @date: 2025/6/5 21:52
 * @description:
 */
@Mapper
public interface GroupInfoMapper extends BaseMapper<GroupInfoDO> {
    @Select("SELECT " +
            "g.group_id, " +
            "g.group_name, " +
            "g.group_owner_id, " +
            "g.group_notice, " +
            "g.join_type, " +
            "g.`status`, " +
            "g.create_time, " +
            "(SELECT nick_name FROM user_info u WHERE u.user_id = g.group_owner_id) groupOwnerNickName, " +
            "(SELECT COUNT(1) FROM user_contact c WHERE c.contact_id = g.group_id) members " +
            "FROM " +
            "group_info g " +
            "ORDER BY " +
            "g.create_time DESC")
    Page<GroupInfoDTO> selectAllGroupInfo(Page<GroupInfoDO> page);
}
